namespace Admin2025.Domain.Entities.App;

public class AppRole : EntityBase
{
    public string RoleName { get; set; } = null!;

    // 数据权限范围：如"All"、"Department"、"Self"
    public string DataScope { get; set; } = "Self";
    public ICollection<AppPermission> Permissions { get; set; } = new List<AppPermission>();

    public void AssignPermission(AppPermission permission)
    {
        // 如果不包含，则添加权限
        if (!Permissions.Contains(permission))
        {
            Permissions.Add(permission);
        }

    }
    public void RemovePermission(AppPermission permission)
    {
        // 如果包含指定权限，则移除
        if (Permissions.Contains(permission))
        {
            Permissions.Remove(permission);
        }

    }

    public bool HasPermission(string permissionCode)
    {
        return Permissions.Any(p => p.Code == permissionCode);
    }
}